<template>
	<view class="main">
		<image class="login-imag" src="../../static/images/login_02.png" mode=""></image>
		
		
		<view class="daohangkuang">
			<view class="shurukuang">
				<view class="shoujihao">
					<input class="input-sjh" type="text" placeholder="请输入手机号" v-model="mobile">
				</view>
				<view class="yamzma">
					<input class="input-sjh" type="text" placeholder="请输入验证码" v-model="code">
					<text v-if='isshowtime' class="huoqu" @tap="yanzhengma">获取验证码</text>
					<text v-else>已发送{{timecode}}</text>
				</view>
			</view>
		</view>
		
		
		<view class="xieyishu">
			<label @tap="Agreement">
				<radio value="false" :checked="User"/>
				<text class="woyi">
					我已阅读并同意
					<span class="yh">《用户使用协议》</span>
					和
					<span class="yh">《隐私协议》</span>
				</text>
			</label>
		</view>
		
		<view class="xiayibu" @click="pwd">下一步</view>
		
	</view>
</template>

<script>
	import Index from '@/apis/index.js'
	export default {
		data() {
			return {
				// 单选状态
				User:false,
				// 获取验证码
				isshowtime:true,
				// 手机号
				mobile:"",
				// 验证码
				code:"",
				// 倒计时
				timecode:10
			}
		},
		methods: {
			// 单选框
			Agreement(){
				this.User=!this.User
			},
			async yanzhengma(){
				if(this.mobile==''){
					this.$message.error('手机号不能为空')
					return
				}
				//手机号是否正确
				const reg = /^1[3-9]\d{9}$/
				if(!reg.test(this.mobile)){
					this.$message.error('请输入正确的手机号')
					return
				}
				let res = await Index.sendcode({mobile:this.mobile})
				console.log(res);
				if(res.errCode==10000){
					this.isshowtime = false
					let timecodedata = setInterval(()=>{
						this.timecode--
						if(this.timecode<=0){
							// 清除定时器
							clearInterval(this.timecodedata)
							this.isshowtime=true
							this.timecode=10
							this.timecodedata=null
						}
					},1000)
					this.$message.none('获取成功')
				}else{
					this.$message.error(res.errMsg)
				}
			},
			// 跳转到确认密码
			async pwd(){
				// 手机号不能为空
				if(this.mobile==''){
					this.$message.error('请输入手机号')
					return
				}
				//手机号是否正确
				const reg = /^1[3-9]\d{9}$/
				if(!reg.test(this.mobile)){
					this.$message.error('请输入正确的手机号')
					return
				}
				// 验证码不能为空
				if(this.code==''){
					this.$message.error('请输入验证码')
					return
				}
				// 验证码是否正确
				const codereg = /^\d{6}$/
				if(!codereg.test(this.code)){
					this.$message.error('验证码不正确')
					return
				}
				if(!this.User){
					this.$message.error('请勾选用户协议')
					return
				}
				let res = await Index.memberregByCode({mobile:this.mobile,code:this.code})
				// console.log(res)
				if(res.errCode==10000){
					let usermobile = res.data
					// console.log(usermobile)
					uni.navigateTo({
						url:`/pages/registerr/registerr?mobile=${usermobile}`
					})
				}else{
					this.$message.error(res.errMsg)
				}
			},
			
		}
	}
</script>

<style>
@import url('../../static/css/register/register.css');
</style>
